import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/Home.vue'),
    meta: {
      title: '首页 - RookieWiki'
    }
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('../views/About.vue'),
    meta: {
      title: '关于 - RookieWiki'
    }
  },
  {
    path: '/help',
    name: 'Help',
    component: () => import('../views/Help.vue'),
    meta: {
      title: '帮助 - RookieWiki'
    }
  },
  {
    path: '/new',
    name: 'New',
    component: () => import('../views/New.vue'),
    meta: {
      title: '添加 - RookieWiki'
    }
  },
  {
    path: '/article/:id',
    name: 'Article',
    component: () => import('../views/Article.vue'),
    meta: {
      title: '文章 - RookieWiki'
    }
  },
  {
    path: '/edit/:id',
    name: 'Edit',
    component: () => import('../views/Edit.vue'),
    meta: {
      title: '编辑 - RookieWiki'
    }
  },
  {
    path: '/articles',
    name: 'Articles',
    component: () => import('../views/Articles.vue'),
    meta: {
      title: '文章列表 - RookieWiki'
    }
  },
  /*
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
    meta: {
      title: '登录 - RookieWiki'
    }
  },
*/
  {
    path: '/newed',
    name: 'Newed',
    component: () => import('../views/Newed.vue'),
    meta: {
      title: '首页 - RookieWiki'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})

export default router
